From f5fe361f432b517452284bd5ca11b28ed3236c44 Mon Sep 17 00:00:00 2001 From: "robertlipe@gmail.com" Date: Wed, 1 Jan 2014 20:00:32 +0000 Subject: [PATCH] Move gbfgets() to QString. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4700 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/gbfile.cc | 7 +++++-- gpsbabel/gbfile.h | 2 +- gpsbabel/magproto.cc | 9 ++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/gpsbabel/gbfile.cc b/gpsbabel/gbfile.cc index af06e9761..60ffaaa14 100644 --- a/gpsbabel/gbfile.cc +++ b/gpsbabel/gbfile.cc @@ -656,7 +656,7 @@ gbfgetc(gbfile* file) * gbfgets: (as fgets) */ -char* +QString gbfgets(char* buf, int len, gbfile* file) { char* result = buf; @@ -682,7 +682,10 @@ gbfgets(char* buf, int len, gbfile* file) } } *buf = '\0'; - return (*result != '\0') ? result : NULL; + + QString rv(result); + return rv; + } /* diff --git a/gpsbabel/gbfile.h b/gpsbabel/gbfile.h index b23f1e923..72c1bde5c 100644 --- a/gpsbabel/gbfile.h +++ b/gpsbabel/gbfile.h @@ -95,7 +95,7 @@ void gbfclose(gbfile* file); gbsize_t gbfread(void* buf, const gbsize_t size, const gbsize_t members, gbfile* file); int gbfgetc(gbfile* file); -char* gbfgets(char* buf, int len, gbfile* file); +QString gbfgets(char* buf, int len, gbfile* file); int gbvfprintf(gbfile* file, const char* format, va_list ap); int gbfprintf(gbfile* file, const char* format, ...); diff --git a/gpsbabel/magproto.cc b/gpsbabel/magproto.cc index 826f39ad5..77fafb623 100644 --- a/gpsbabel/magproto.cc +++ b/gpsbabel/magproto.cc @@ -43,7 +43,7 @@ static int broken_sportrak; #define debug_serial (global_opts.debug_level > 1) -static char* termread(char* ibuf, int size); +static QString termread(char* ibuf, int size); static void termwrite(char* obuf, int size); static void mag_readmsg(gpsdata_type objective); static void mag_handon(void); @@ -420,13 +420,12 @@ mag_readmsg(gpsdata_type objective) int isz; unsigned int isum; char* isump; - char* gr; int retrycnt = 20; retry: - gr = termread(ibuf, sizeof(ibuf)); + QString gr = termread(ibuf, sizeof(ibuf)); - if (!gr) { + if (gr.isEmpty()) { if (!got_version) { /* * The 315 can take up to six seconds to respond to @@ -597,7 +596,7 @@ terminit(const char* portname, int create_ok) } } -static char* termread(char* ibuf, int size) +static QString termread(char* ibuf, int size) { if (is_file) { return gbfgets(ibuf, size, magfile_h); -- 2.30.2